// 防抖立即执行版
export default function debounce (fn, time) {
  let timer = null
  return function () {
    const context = this
    const args = arguments
    // eslint-disable-next-line no-irregular-whitespace
    if (timer) clearTimeout(timer)  // 清除前一个定时器
    const callNow = !timer
    timer = setTimeout(() => {
      timer = null
    }, time || 500)
    if (callNow) fn.apply(context, args)
  }
}
